package com.xmut.mall.order.controller;

import java.util.Arrays;
import java.util.Map;

import com.xmut.mall.order.annotation.CheckJwt;
import com.xmut.mall.order.searchparam.AfterSaleSearchParams;
import com.xmut.mall.order.to.*;
import com.xmut.mall.order.utils.RespBean;
import com.xmut.mall.order.vo.PageVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.xmut.mall.order.entity.AfterSaleEntity;
import com.xmut.mall.order.service.AfterSaleService;
import com.xmut.mall.order.utils.PageUtils;
import com.xmut.mall.order.utils.R;

@RestController
@RequestMapping("order/aftersale")
public class AfterSaleController {
    @Autowired
    private AfterSaleService afterSaleService;

    /**
     * 获取售后物流信息
     * @param sn
     * @return
     */
    @CheckJwt
    @GetMapping("/getAfterSaleDeliveryTraces/{sn}")
    public RespBean getAfterSaleDeliveryTraces(@PathVariable String sn){
        return afterSaleService.getAfterSaleDeliveryTraces(sn);
    }

    /**
     * 卖家确认收货
     * @param dto
     * @return
     */
    @CheckJwt
    @PostMapping("/confirm")
    public RespBean confirm(@RequestBody SellerAfterSaleConfirmDto dto){
        return afterSaleService.confirm(dto);
    }

    /**
     * 取消售后
     * @param dto
     * @return
     */
    @CheckJwt
    @PostMapping("/cancel")
    public RespBean cancel(@RequestBody CancelAfterSaleDto dto){
        return afterSaleService.cancel(dto);
    }

    /**
     * 获取售后退货商品的售后物流信息
     * @param sn
     * @return
     */
    @CheckJwt
    @GetMapping("/getAfterSaleTraces/{sn}")
    public RespBean getAfterSaleTraces(@PathVariable String sn){
        return afterSaleService.getAfterSaleTraces(sn);
    }

    /**
     * 卖家 退货 物流接口
     * @param dto
     * @return
     */
    @CheckJwt
    @PostMapping("/BuyerDelivery")
    public RespBean BuyerDelivery(@RequestBody BuyerDeliveryDto dto){
        return afterSaleService.BuyerDelivery(dto);
    }

    /**
     * 审核售后申请
     * @param dto
     * @return
     */
    @CheckJwt
    @PostMapping("/review")
    public RespBean review(@RequestBody SellerAfterSaleReviewDto dto){
        return afterSaleService.review(dto);
    }

    /**
     * 获取商家售后收件地址
     * @param sn
     * @return
     */
    @CheckJwt
    @GetMapping("/getStoreAfterSaleAddress/{sn}")
    public RespBean getStoreAfterSaleAddress(@PathVariable String sn){
        return afterSaleService.getStoreAfterSaleAddress(sn);
    }

    /**
     * 根据售后的sn号码获取售后的详情信息
     * @param sn
     * @return
     */
    @CheckJwt
    @GetMapping("/getAfterSaleDetail/{sn}")
    public RespBean getAfterSaleDetail(@PathVariable String sn){
        return afterSaleService.getAfterSaleDetail(sn);
    }

    /**
     * 获取售后数据的分页信息
     * @param params
     * @return
     */
    @CheckJwt
    @PostMapping("/getAfterSalePage")
    public RespBean getAfterSalePage(@RequestBody AfterSaleSearchParams params){
        PageVO vo = new PageVO();
        BeanUtils.copyProperties(params,vo);
        return afterSaleService.getAfterSalePage(vo,params);
    }

    /**
     * 申请售后信息
     * @param dto
     * @return
     */
    @CheckJwt
    @PostMapping("/applyAfterSale")
    public RespBean applyAfterSale(@RequestBody AfterSaleDTO dto){
        return afterSaleService.applyAfterSale(dto);
    }

    /**
     * 获取售后信息
     * @param params
     * @return
     */
    @CheckJwt
    @PostMapping("/getAfterSaleInfo")
    public RespBean getAfterSaleInfo(@RequestBody Map<String,Object> params){
        return afterSaleService.getAfterSaleInfo(params);
    }


}
